using System.ComponentModel.DataAnnotations;

namespace AiQiuQuan.Sport.Model.Models
{
    /// <summary>
    /// 修改私教预约dto
    /// </summary>
    public class CoacherBookUpdateDto : IValidatableObject
    {
        /// <summary>
        /// 业务ID
        /// </summary>
        [Required]
        public Guid BusinessId { get; set; }

        /// <summary>
        /// 开始时间
        /// </summary>
        [Required(AllowEmptyStrings = false, ErrorMessage = "开始时间必填")]
        public string StartTime { get; set; }

        /// <summary>
        /// 结束时间
        /// </summary>
        [Required(AllowEmptyStrings = false, ErrorMessage = "结束时间必填")]
        public string EndTime { get; set; }

        /// <summary>
        /// 场馆ID
        /// </summary>
        [Required(ErrorMessage = "场馆ID必填")]
        public Guid VenueId { get; set; }

        /// <summary>
        /// 场地
        /// </summary>
        [Required(AllowEmptyStrings = false, ErrorMessage = "场地必填")]
        public string Site { get; set; }

        /// <summary>
        /// 学员ID列表
        /// </summary>
        [Required]
        [MinLength(1)]
        public List<Guid> StudentIdList { get; set; }

        /// <summary>
        /// validate
        /// </summary>
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (!TimeSpan.TryParse(StartTime, out var start))
            {
                yield return new ValidationResult("开始时间不正确");
                yield break;
            }

            if (!TimeSpan.TryParse(EndTime, out var end))
            {
                yield return new ValidationResult("结束时间不正确");
                yield break;
            }

            if (start >= end)
            {
                yield return new ValidationResult("开始时间大于结束时间");
                yield break;
            }
        }
    }
}
